CRM 2011 JavaScript passing parameter to SSRS Reports

I had a requirement to generate report from the ribbon button, and my report takes the record’s GUID as its parameter.

Passing parameters to SSRS reports is nothing but, we need to provide the Record’s GUID, Entity type code and Parameter value as the URL. So I have written a Jscript to get GUID value of the record. My Report URL is like:

window.open(“/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=” +RdlName+ “&id=%7b” +ReportID+ “%7d&records=” +ID+ “&recordstype=” +ETC+ “&p:Parameter=” +ID + “”);

“RdlName” denotes the name of RDL that you created (Open the SSRS Report Project and copy the rdl name from there).

“ReportID” is the GUID of that report

“ETC” denotes the Entity Type Code

“Parameter” is nothing but the parameter name that is used in reports (Open the SSRS Report Project and copy the parameter name from there)

“ID” denotes the parameter value. Here I have passed the Record’s GUID as a parameter. You can fetch the parameter value in Jscript and use that here.

Below is the Script that I have written for opening Report:

function viewReport() {

var ID = Xrm.Page.data.entity.getId();

window.open(“/crmreports/viewer/viewer.aspx?action=run&context=records&helpID=” +RdlName+ “&id=%7b” +ReportID+ “%7d&records=” + ID + “&recordstype=” +ETC+ “&p:Parameter=” +ID + “”);

}

Note: In my case, both Record ID and Parameter are same, as I am passing Record GUID as parameter value.

Cheers,

Naren

4 thoughts on “CRM 2011 JavaScript passing parameter to SSRS Reports

  1. Jim Mead says:

    Thank you for this. I think we can use it. Our customers would like the idea of printing a contact or account profile sheet with out going through additional clicks on Run Report.

    We would also like to call a stored procedure from a ribbon button. What would be the best way to do this?

    Thanks.

    • Naren says:

      Hi Jim,
      If you are using CRM’13 with Google Chrome, there is a default option “Print Preview” on the Navigation Pane of CRM. This will give you the Screenshot of selected record as it is. If you want the same functionality without using Reports for other browsers, You have to download respective add-ins.

      You can’t directly call Stored Procedures in Ribbon buttons. instead You can call the scripts and URL’s that will serve this purpose.

Leave a comment